package com.weilx959.spt.plugin.e2sp;

import com.weilx959.spt.core.config.Config;
import com.weilx959.spt.core.constants.ThemeEnum;
import com.weilx959.spt.core.interfaces.Controller;
import com.weilx959.spt.core.interfaces.SPTPlugin;
import com.weilx959.spt.core.utils.FXMLUtil;
import com.weilx959.spt.plugin.e2sp.constant.ExcelToSqlConstants;
import com.weilx959.spt.plugin.e2sp.controller.ExcelToSqlConfigController;
import com.weilx959.spt.plugin.e2sp.controller.ExcelToSqlController;
import com.weilx959.spt.plugin.e2sp.utils.ResourceBundleUtil;
import javafx.scene.Node;
import lombok.extern.slf4j.Slf4j;

import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.ResourceBundle;

/**
 * excel to sql插件
 *
 * @author weilx
 * @since 2024-04-16
 */
@Slf4j
public class Excel2SqlPluginImpl implements SPTPlugin {
    private final ExcelToSqlController controller;

    private final Config config;

    private final ResourceBundle bundle = ResourceBundleUtil.get();

    public Excel2SqlPluginImpl() {
        controller =  FXMLUtil.getController(this.getClass(), ExcelToSqlConstants.EXCEL_TO_SQL_VIEW, bundle);
        final ExcelToSqlConfigController configController = FXMLUtil.getController(this.getClass(),
            ExcelToSqlConstants.EXCEL_TO_SQL_CONFIG_VIEW, bundle);
        config = configController.getConfig();
    }

    @Override
    public String getID() {
        return "7a89787a-1d97-46f2-9aca-2352639ee578";
    }

    @Override
    public String getName() {
        return bundle.getString("e2s.plugin.name");
    }

    @Override
    public String getDescription() {
        return bundle.getString("e2s.plugin.description");
    }

    @Override
    public String getVersion() {
        return bundle.getString("e2s.plugin.version");
    }

    @Override
    public String getAuthor() {
        return bundle.getString("e2s.plugin.author");
    }

    @Override
    public Controller getController() {
        return controller;
    }

    @Override
    public Node getView() {
        return controller.getRootPane();
    }

    @Override
    public Config getConfig() {
        return config;
    }

    @Override
    public List<String> getStylesheets(ThemeEnum theme) {
        if (Objects.isNull(theme)) {
            return Collections.emptyList();
        }
        return switch (theme) {
            case DARK -> List.of("com/weilx959/spt/plugin/e2sp/theme/dark.css");
            case LIGHT -> List.of("com/weilx959/spt/plugin/e2sp/theme/light.css");
            default -> Collections.emptyList();
        };
    }

    @Override
    public String getIconStyle() {
        return "e2s-icon";
    }

    @Override
    public Integer getOrder() {
        return SPTPlugin.super.getOrder() + 1;
    }
}
